<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增申请用油')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-gasoline-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">归属主卡号：</label>
                <div class="col-sm-8">
                    <div class="col-sm-8">
                        <select class="form-control noselect2 selectpicker" id="chAffiliation">
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">副油卡卡号：</label>
                <div class="col-sm-8">
                    <div class="col-sm-8">
                        <select class="form-control noselect2 selectpicker" id="chNumber">
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">充值金额：</label>
                <div class="col-sm-8">
                    <input name="chTopup" class="form-control" type="text" id="chTopup" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">充值时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="chTime" class="form-control" placeholder="yyyy-MM-dd" type="text" id="chTime" required>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上传里程记录：</label>
                <div class="col-sm-8">
                    <input name="chFile" class="form-control" type="file" id="chFile">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">备注：</label>
                <div class="col-sm-8">
                    <input name="chRemark" class="form-control" type="text" id="chRemark" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "ruoyi/gasoline"
        var prefixs = ctx + "ruoyi/examine"
        var prefixd = ctx + "ruoyi/Maingasoline"
        $("#form-gasoline-add").validate({
            focusCleanup: true
        });
        uplike();
        function submitHandler() {
            if ($.validate.form()) {
                uploadFile();
            }
        }
        function uplike(){
            $.ajax({
                url: prefixd + "/lists",
                type: "post",
                dataType:"json",
                data: {},
                success: function(data){
                    if(data.length>0){
                        //value='"+data[i].tName+","+data[i].tName+"'
                        for(i in data){
                            $("#chAffiliation").append("<option>"+data[i].mNumber+"</option>")
                        }
                    }else{
                        $("#chAffiliation").append("<option>暂无数据</option>")
                    }
                }
            });
            $.ajax({
                url: prefixs + "/lists",
                type: "post",
                dataType:"json",
                data: {},
                success: function(data){
                    if(data.length>0){
                        //value='"+data[i].tName+","+data[i].tName+"'
                        for(i in data){
                            $("#chNumber").append("<option>"+data[i].eChildcard+"</option>")
                        }
                    }else{
                        $("#chNumber").append("<option>暂无数据</option>")
                    }
                }
            });
        }
        function uploadFile() {
            var formData = new FormData();
            if ($('#chFile')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            var options = $("#chNumber option:selected");
            var chNumber = options.val();
            var option = $("#chAffiliation option:selected");
            var chAffiliation = option.val();
            formData.append('chNumber',chNumber);
            formData.append('chAffiliation',chAffiliation);
            formData.append('chTopup', $("#chTopup").val());
            formData.append('chTime', $("#chTime").val());
            formData.append('chRemark', $("#chRemark").val());
            formData.append('file', $("#chFile")[0].files[0]);
            $.ajax({
                url: prefix + "/add/",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }
        $("input[name='chTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>